package com.ydd.controller.admin;

import com.ydd.dto.YddAdvimgPageDTO;
import com.ydd.dto.YddadvimgDTO;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.YddAdvimgService;
import com.ydd.vo.YddAdvimgVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "广告图管理")
@RequestMapping("ydd_advimg")
public class YddAdvimgController {

    @Autowired
    private YddAdvimgService yddAdvimgService;

    @ApiOperation("GET 广告图列表-分页")
    @GetMapping("/list")
    public Result<PageResult> yddAdvimgPage(YddAdvimgPageDTO yddAdvimgPageDTO){
        log.info("广告图列表-分页: {}", yddAdvimgPageDTO);
        PageResult pageResult = yddAdvimgService.pageQueryList(yddAdvimgPageDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/rowInfo")
    @ApiOperation("GET 广告图详情")
    public Result<YddAdvimgVO> rowInfo(Integer id){
        log.info("GET 广告图详情: {}", id);
        YddAdvimgVO yddAdvimgVO = yddAdvimgService.getRowInfoById(id);
        return Result.success(yddAdvimgVO);
    }

    @GetMapping("/del")
    @ApiOperation("GET 广告图删除")
    public Result deleteById(Integer id){
        log.info("GET 广告图删除: {}", id);
        yddAdvimgService.deleteByYddId(id);
        return Result.success();
    }

    @PostMapping("/add")
    @ApiOperation("GET 广告图添加")
    public Result addYddadvimg(@RequestBody YddadvimgDTO yddadvimgDTO){
        log.info("GET 广告图添加: {}", yddadvimgDTO);
        yddAdvimgService.addYddadvimg(yddadvimgDTO);
        return Result.success();
    }

    @PostMapping("/update")
    @ApiOperation("POST 广告图修改")
    public Result updateYddAdvimg(@RequestBody YddadvimgDTO yddadvimgDTO){
        log.info("POST 广告图修改: {}", yddadvimgDTO);
        yddAdvimgService.YddAdvimgUpdate(yddadvimgDTO);
        return Result.success();
    }
}

